#!/bin/env python
import glob

def plot_out( rundir, bh_id, plot_item ) :
    xdata = []
    ydata = []

    agn_kick_files = glob.glob( rundir+'/logs/AGN_kick*' )

    # Loop over AGN_kick files and collect xdata and ydata
    for file in agn_kick_files :
        for line in open(file,'r') :
            if not line.startswith('#') and line.startswith( bh_id ) and len(line.split()) > 10 :
                xval, yval = plot_calc( plot_item, line )
                xdata.append( xval )
                ydata.append( yval )
                
    return xdata, ydata

def plot_calc( plot_item, line ) :
    cols = line.split()
    if plot_item['plotcalc'] == 'None' :
        if plot_item['colx'] == 1 :
            xval = 1./float(cols[plot_item['colx']])
        else :
            xval = float(cols[plot_item['colx']])
        yval = float(cols[plot_item['coly']])
        
    return xval, yval
